<template>
  <view>
    <!-- 插件部分-->
    <ss-select-city v-if="isRouterAlive" :hotCitys="hotCitys" :historyCity="historyCity" :value="value" />
    <mapcompt @getmap="getmap" @fail="fail"></mapcompt>
  </view>
</template>

<script>
import ssSelectCity from '@/components/ss-select-city/ss-select-city.vue';
import { findHotCity } from '@/service/findShop/findShop.service.js'
// import { gettokenStore } from '../../../store/dataCache.js';
import mapcompt from '@/components/mapCompt.vue';
export default {
  props: {},
  data() {
    return {
      hotCitys: [],
      value: '定位中...',
      isRouterAlive: true,
      historyCity: []
    };
  },
  onLoad(option) {
    /* 获取热门城市数据*/
    this.getHotCityList();
    /* 获取历史搜索本地存储*/
    this.gethistoryCityList();
  },
  components: {
    ssSelectCity,
    mapcompt
  },
  mounted() {},
  methods: {
    fail(){
      this.value ='上海'
    },
    getmap(obj) {
      this.value = obj.province;
      this.isRouterAlive = false;
      this.$nextTick(() => (this.isRouterAlive = true));
    },
    getHotCityList() {
      // let token = gettokenStore();
      findHotCity({},res => {
        let result = [];
        for (let i in res.data) {
          result.push(res.data[i].value);
        }
        this.hotCitys = result;
      })
    },
    gethistoryCityList() {
      var arr = uni.getStorageSync('historyCity');
      if(arr){
        arr.pop()
        this.historyCity = arr.slice(0,6)
      }
      
    }
  }
};
</script>

<style scoped></style>
